package com.dlc.felear.xiaoensale.utils;

import android.util.Log;

import java.text.DecimalFormat;
import java.util.regex.Pattern;

public class NumToStringUtil {
    public static String spitDouble(double data) {
        String p = "";
        DecimalFormat df = new DecimalFormat(".00");
        p = df.format(Math.abs(data));
        if (p.indexOf('.') == 0) {
            p = "0" + p;
        }
        if (data < 0) {
            p = "-" + p;
        }
        return p;
    }

    public static String spitDouble(double data, int ws) {
        String p = "";
        DecimalFormat df = null;
        if (ws <= 1) {
            df = new DecimalFormat(".0");
        } else if (ws == 2) {
            df = new DecimalFormat(".00");
        } else if (ws == 3) {
            df = new DecimalFormat(".000");
        }

        p = df.format(Math.abs(data));
        if (p.indexOf('.') == 0) {
            p = "0" + p;
        }
        if (data < 0) {
            p = "-" + p;
        }
        Log.e("qindaji","p="+p+" data="+data);
        return p;
    }

    public static String spitFloat(float data) {
        String p = "";
        DecimalFormat df = new DecimalFormat(".00");
        p = df.format(data);
        if (p.indexOf('.') == 0) {
            p = "0" + p;
        }
        return p;
    }

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }
}
